package com.renrendoc.network.flow.ana;

import com.renrendoc.network.flow.beans.out.TopNPage;
import org.apache.flink.api.common.functions.AggregateFunction;
import org.apache.flink.api.java.tuple.Tuple3;

/**
 * topn agg
 */
public class TopPageAgg implements AggregateFunction<Long, Tuple3<Long, Long, Long>, TopNPage> {
    @Override
    public Tuple3<Long, Long, Long> createAccumulator() {
        return Tuple3.of(0L, 0L, 0L);
    }

    @Override
    public Tuple3<Long, Long, Long> add(Long aLong, Tuple3<Long, Long, Long> longLongTuple3) {
        return Tuple3.of(aLong, longLongTuple3.f1 + 1, 0L);
    }

    @Override
    public TopNPage getResult(Tuple3<Long, Long, Long> longLongTuple3) {
        return new TopNPage(longLongTuple3.f0, longLongTuple3.f1, longLongTuple3.f2);
    }

    @Override
    public Tuple3<Long, Long, Long> merge(Tuple3<Long, Long, Long> longLongTuple3, Tuple3<Long, Long, Long> acc1) {
        return null;
    }
}
